package 力扣日常刷题.木23一月.第09天309;

/**
 * @author 帅小伙
 * @date 2022/3/9
 * @description
 */
public class Demo28构建乘积数组 {

    public static void main(String[] args) {
        constructArr(new int[]{1, 2, 0, 4, 5});
    }

    public static int[] constructArr(int[] a) {
        int[] res = new int[a.length];
        int left = 1;
        for (int i = 0; i < a.length; i++) {
            res[i] = left;
            left *= a[i];
        }
        int right = 1;
        for (int i = a.length - 1; i >= 0; i--) {
            res[i] *= right;
            right *= a[i];
        }
        return res;
    }
}
